﻿using System;
using System.Security.Cryptography;
using System.Text;

namespace VirtualTournaments.Business.Users
{
	public class Password
	{
		private string password;

		public Password(string password)
		{
			this.password = this.EncodePassword(password);
		}

		private string EncodePassword(string password)
		{
			MD5 md5 = new MD5CryptoServiceProvider();
			Byte[] passwordBytes = ASCIIEncoding.Default.GetBytes(password);
			Byte[] encodedBytes = md5.ComputeHash(passwordBytes);
			return BitConverter.ToString(encodedBytes);
		}

		public bool ValidatePassword(string password)
		{
			return this.password.Equals(this.EncodePassword(password));
		}

		public string Pasword
		{
			get { return password; }
			protected set { password = value; }
		}
	}
}
